home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / set_param.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-10  |  6.5 KB  |  234 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <string.h>
  20.  
  21. #include "memory.h"
  22. #include "ctyp_dec.h"
  23. #include "rec.h"
  24. #include "window.h"
  25. #include "ed_dec.h"
  26. #include "cmd_enum.h"
  27. #include "cmd_dec.h"
  28.  
  29. /******************************************************************************\
  30. |Routine: inscmp
  31. |Callby: set_param
  32. |Purpose: Does what strcmp does, without case-sensitivity.
  33. |Arguments:
  34. |    s1,s2 are the strings being compared.
  35. \******************************************************************************/
  36. Int inscmp(s1,s2)
  37. register Char *s1,*s2;
  38. {
  39.     Char l1[128],l2[128];
  40.     register Char *p,*q,c;
  41.  
  42.     for(p = (Char *)s1,q = l1;(c = *p++);)
  43.         *q++ = tolower(c);
  44.     *q = '\0';
  45.     for(p = (Char *)s2,q = l2;(c = *p++);)
  46.         *q++ = tolower(c);
  47.     *q = '\0';
  48.     return(strcmp(l1,l2));
  49. }
  50.  
  51. /******************************************************************************\
  52. |Routine: decode_error
  53. |Callby: set_param
  54. |Purpose: Handles bad user input to numeric questions.
  55. |Arguments:
  56. |    p is the description of what the user was asked for.
  57. \******************************************************************************/
  58. void decode_error(p)
  59. Char *p;
  60. {
  61.     Char buf[256];
  62.  
  63.     strcpy(buf,"Unable to understand the ");
  64.     strcat(buf,p);
  65.     strcat(buf,".");
  66.     slip_message(buf);
  67.     wait_message();
  68. }
  69.  
  70. /******************************************************************************\
  71. |Routine: set_param
  72. |Callby: command
  73. |Purpose: Lets user set editing parameters.
  74. |Arguments:
  75. |    choice is the number of the paramter user wants to set.
  76. |    buf is the buffer containing the value the user wants for the parameter.
  77. |    bufl is the length of the user buffer.
  78. |    l is the length of the data in buf.
  79. |    i is the current position in buf.
  80. \******************************************************************************/
  81. void set_param(choice,buf,bufl,l,i)
  82. Int choice,bufl,l,i;
  83. Char *buf;
  84. {
  85.     Int j,crterm;
  86.  
  87.     for(;i < l;i++)    /* skip leading whitespace before value */
  88.         if(!isspace(buf[i]))
  89.             break;
  90.     if(i == l || (choice >= (int)PAR_WORD && choice <= (int)PAR_PARAGRAPH))    /* WORD and PARAGRAPH require explicit input */
  91.     {
  92.         if(choice >= (int)PAR_WORD && choice <= (int)PAR_PARAGRAPH)
  93.             crterm = 0;
  94.         else
  95.             crterm = 1;
  96.         if(!(l = inquire(prompts[choice],buf,bufl,crterm)))
  97.             return;
  98.         buf[l] = '\0';
  99.         i = 0;
  100.     }
  101.     switch(choice)
  102.     {
  103.         case PAR_SHELL:
  104.             if((j = strlen(buf + i)) > sizeof(USERSHELL) - 1)
  105.                 j = sizeof(USERSHELL) - 1;
  106.             memcpy(USERSHELL,buf + i,j);
  107.             USERSHELL[j] = '\0';
  108.             break;
  109.         case PAR_TABS:
  110.             for(j = 0;j < TAB_SETUPS;j++)
  111.                 if(!inscmp(buf + i,TAB_NAME[j]))
  112.                     break;
  113.             if(j == TAB_SETUPS)
  114.             {
  115.                 strcpy(buf,"Unknown tab setup. Use one of (");
  116.                 for(j = 0;j < TAB_SETUPS;j++)
  117.                 {
  118.                     strcat(buf,TAB_NAME[j]);
  119.                     if(j < TAB_SETUPS - 2)
  120.                         strcat(buf,", ");
  121.                     else if(j < TAB_SETUPS - 1)
  122.                         strcat(buf," or ");
  123.                 }
  124.                 strcat(buf,").");
  125.                 slip_message(buf);
  126.                 wait_message();
  127.             }
  128.             else
  129.             {
  130.                 CUR_TAB_SETUP = j;
  131.                 CURCOL = get_column(CURREC,CURBYT);
  132.                 ref_display();
  133.             }
  134.             break;
  135.         case PAR_WRAP:
  136.             if((my_sscanf(buf + i,"%d",&j)) != 1)
  137.                 decode_error(prompts[choice]);
  138.             else
  139.                 WRAP_MARGIN = j;
  140.             break;
  141.         case PAR_SECTION:
  142.             if((my_sscanf(buf + i,"%d",&j)) != 1)
  143.                 decode_error(prompts[choice]);
  144.             else
  145.                 SECTION_LINES = j;
  146.             break;
  147.         case PAR_WORD:
  148.             memcpy(WORD_DELIMITERS,buf,l);
  149.             NWORD_DELIMITERS = l;
  150.             init_word_table(NWORD_DELIMITERS,WORD_DELIMITERS);
  151.             break;
  152.         case PAR_PAGE:
  153.             memcpy(PAGE_BREAK,buf,l);
  154.             PAGE_BREAK_LENGTH = l;
  155.             break;
  156.         case PAR_PARAGRAPH:
  157.             memcpy(PARAGRAPH_BREAK,buf,l);
  158.             PARAGRAPH_BREAK_LENGTH = l;
  159.             break;
  160.         case PAR_SEARCH:
  161.             if((choice = parse_command(0,buf,bufl,&l,&i,smodes,NUM_SMODES,"search mode")) >= 0)
  162.             {
  163.                 if(choice == (int)SMODE_TABLE_DRIVEN)    /* SET SEARCH TABLE */
  164.                 {
  165.                     if(!set_search_table(SEARCH_TABLE))
  166.                     {
  167.                         SEARCH_FLAGS[((int)SMODE_TABLE_DRIVEN) >> 1] = 'n';
  168.                         slip_message("Unable to read the search table.");
  169.                         wait_message();
  170.                         break;
  171.                     }
  172.                 }
  173.                 SEARCH_FLAGS[choice >> 1] = *smodes[choice];
  174.             }
  175.             break;
  176.         case PAR_STABLE:
  177.             if((j = strlen(buf + i)) > sizeof(SEARCH_TABLE) - 1)
  178.                 j = sizeof(SEARCH_TABLE) - 1;
  179.             memcpy(SEARCH_TABLE,buf + i,j);
  180.             SEARCH_TABLE[j] = '\0';
  181.             break;
  182.         case PAR_CLOSE_PARENS:
  183.             if((choice = parse_command(0,buf,bufl,&l,&i,offon,3,"paren matching status")) >= 0)
  184.                 CLOSE_PARENS = ((choice == 2)? !CLOSE_PARENS : choice);
  185.             break;
  186.         case PAR_PARENS:
  187.             if((j = strlen(buf + i)) > sizeof(PAREN_STRING) - 1)
  188.                 j = sizeof(PAREN_STRING) - 1;
  189.             memcpy(PAREN_STRING,buf + i,j);
  190.             PAREN_STRING[j] = '\0';
  191.             PAREN_STRING_LENGTH = j;
  192.             break;
  193.         case PAR_DEFAULT:
  194.             if((j = strlen(buf + i)) > sizeof(DEFAULT_EXT) - 1)
  195.                 j = sizeof(DEFAULT_EXT) - 1;
  196.             memcpy(DEFAULT_EXT,buf + i,j);
  197.             DEFAULT_EXT[j] = '\0';
  198.             DEFAULT_EXT_LENGTH = j;
  199.             break;
  200.         case PAR_AUTO_TABS:
  201.             if((choice = parse_command(0,buf,bufl,&l,&i,offon,3,"auto tabs status")) >= 0)
  202.                 TAB_AUTO = ((choice == 2)? !TAB_AUTO : choice);
  203.             break;
  204.         case PAR_CFRIENDLY:
  205.             if((choice = parse_command(0,buf,bufl,&l,&i,offon,3,"C-friendly status")) >= 0)
  206.                 CFRIENDLY = ((choice == 2)? !CFRIENDLY : choice);
  207.             break;
  208.         case PAR_BOXCUT:
  209.             if((choice = parse_command(0,buf,bufl,&l,&i,offon,3,"box cut status")) >= 0)
  210.                 BOXCUT = ((choice == 2)? !BOXCUT : choice);
  211.             break;
  212.         case PAR_AUTOWRAP:
  213.             if((choice = parse_command(0,buf,bufl,&l,&i,offon,3,"auto wrap")) >= 0)
  214.                 AUTOWRAP = ((choice == 2)? !AUTOWRAP : choice);
  215.             break;
  216.         case PAR_CASE:
  217.             if((choice = parse_command(0,buf,bufl,&l,&i,cases,NUM_CASES,"case change")) >= 0)
  218.                 CASECHANGE = choice;
  219.             break;
  220.         case PAR_OVERSTRIKE:
  221.             if((choice = parse_command(0,buf,bufl,&l,&i,offon,3,"overstrike status")) >= 0)
  222.                 OVERSTRIKE = ((choice == 2)? !OVERSTRIKE : choice);
  223.             break;
  224.         case PAR_GREPMODE:
  225.             if((choice = parse_command(0,buf,bufl,&l,&i,grepmodes,3,"GREP mode")) >= 0)
  226.                 GREPMODE = ((choice == 2)? !GREPMODE : choice);
  227.             break;
  228.         case PAR_WILDCARD:
  229.             WILDCARD = buf[i];
  230.             break;
  231.     }
  232. }
  233.  
  234.